<?php
/**
 * Created by PhpStorm.
 * User: wenqiang.yq@gmail.com
 * Date: 16-3-2
 * Time: 下午10:39
 */

namespace ElasticSearch;


class EsTools
{

    /**
     * 是否二维数组
     * @param $datas
     * @return bool
     */
    static public function isMultiArray($datas)
    {
        return is_array($datas) && is_array(current($datas));
    }

    /**
     * 构建特殊的uri
     * @param $hosts
     * @param $type
     * @return string
     */
    static public function specialUri($hosts, $type)
    {
        return self::baseUri($hosts, $type);
    }

    /**
     * 构建基础的Uri
     * @param $hosts
     * @param $index
     * @param $type
     * @param null $primaryKey
     * @return string
     */
    static public function baseUri($hosts, $index = "", $type = "", $primaryKey = NULL)
    {
        if (!preg_match('/^(http|https)/', $hosts)) {
            $hosts = "http://" . $hosts;
        }
        $uri = $hosts;
        if ($uri) {
            $uri .= "/" . $index;
        }
        if ($type) {
            $uri .= "/" . $type;
        }
        if ($primaryKey) {
            $uri .= "/" . $primaryKey;
        }
        return $uri;
    }
}